<?php

namespace App\Http\Controllers\Backend;

use App\Models\Notice;
use App\Models\User;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Auth;

class NoticeController extends Controller
{
    //列表
    public function index()
    {
        $key=\request('key');
        $notices=Notice::paginate(10);
        return view('backend.notice.index',compact('notices','key'));
    }
    //创建页面
    public function create()
    {
        return view('backend.notice.add');
    }
    //储存行为
    public function store()
    {
        //验证
        $this->validate(\request(),[
            'title' => 'required|min:2|max:20',
            'content' => 'required'
        ]);
        $notice=Notice::create(\request(['title','content']));
        //分发通知
        dispatch(new \App\Jobs\SendMessage($notice));
        return redirect(admin_prefix().'/notices');

    }
}
